<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['homePageSet:homePageSet:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['homePageSet:homePageSet:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['homePageSet:homePageSet:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['homePageSet:homePageSet:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="homePageSetList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="视频一" align="center" prop="videoOne" />
      <el-table-column label="视频二" align="center" prop="videoTwo" /> -->
      <el-table-column label="文字描述一" align="center" prop="fieldOne" />
      <el-table-column label="文字描述二" align="center" prop="fieldTwo" />
      <el-table-column label="文字描述三" align="center" prop="fieldThree" />
      <el-table-column label="文字描述四" align="center" prop="fieldFour" />
      <!-- <el-table-column label="文字描述五" align="center" prop="fieldFive" />
      <el-table-column label="文字描述六" align="center" prop="fieldSix" />
      <el-table-column label="文字描述七" align="center" prop="fieldSeven" />
      <el-table-column label="比例" align="center" prop="fieldEight" />
      <el-table-column label="文字描述九" align="center" prop="fieldNine" />
      <el-table-column label="文字描述十" align="center" prop="fieldTen" />
      <el-table-column label="文字描述十一" align="center" prop="fieldEleven" />
      <el-table-column label="文字描述十二" align="center" prop="fieldTwelve" /> -->
      <!-- <el-table-column
        label="文字描述十三"
        align="center"
        prop="fieldThirteen"
      />
      <el-table-column
        label="文字描述十四"
        align="center"
        prop="fieldFourteen"
      />
      <el-table-column
        label="文字描述十五"
        align="center"
        prop="fieldFifteen"
      /> -->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['homePageSet:homePageSet:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['homePageSet:homePageSet:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改首页设置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <!--  -->
        <el-form-item label="视频一" prop="videoOne">
          <imageUpload v-model="form.videoOne" />
        </el-form-item>
        <el-form-item label="视频二" prop="videoTwo">
          <imageUpload v-model="form.videoTwo" />
        </el-form-item>
        <el-form-item label="文字描述一" prop="fieldOne">
          <el-input
            v-model="form.fieldOne"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述二" prop="fieldTwo">
          <el-input
            v-model="form.fieldTwo"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述三" prop="fieldThree">
          <el-input
            v-model="form.fieldThree"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述四" prop="fieldFour">
          <el-input
            v-model="form.fieldFour"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述五" prop="fieldFive">
          <el-input
            v-model="form.fieldFive"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述六" prop="fieldSix">
          <el-input
            v-model="form.fieldSix"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述七" prop="fieldSeven">
          <el-input
            v-model="form.fieldSeven"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="比例" prop="fieldEight">
          <el-input
            v-model="form.fieldEight"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述九" prop="fieldNine">
          <el-input
            v-model="form.fieldNine"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述十" prop="fieldTen">
          <el-input
            v-model="form.fieldTen"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述十一" prop="fieldEleven">
          <el-input
            v-model="form.fieldEleven"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述十二" prop="fieldTwelve">
          <el-input
            v-model="form.fieldTwelve"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述十三" prop="fieldThirteen">
          <el-input
            v-model="form.fieldThirteen"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述十四" prop="fieldFourteen">
          <el-input
            v-model="form.fieldFourteen"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="文字描述十五" prop="fieldFifteen">
          <el-input
            v-model="form.fieldFifteen"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listHomePageSet,
  getHomePageSet,
  delHomePageSet,
  addHomePageSet,
  updateHomePageSet,
} from "@/api/homePageSet/homePageSet";
import { imageUrl } from "@/config";
export default {
  name: "HomePageSet",
  data() {
    return {
      // 遮罩层
      imageUrl,
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 首页设置表格数据
      homePageSetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        videoOne: null,
        videoTwo: null,
        fieldOne: null,
        fieldTwo: null,
        fieldThree: null,
        fieldFour: null,
        fieldFive: null,
        fieldSix: null,
        fieldSeven: null,
        fieldEight: null,
        fieldNine: null,
        fieldTen: null,
        fieldEleven: null,
        fieldTwelve: null,
        fieldThirteen: null,
        fieldFourteen: null,
        fieldFifteen: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询首页设置列表 */
    getList() {
      this.loading = true;
      listHomePageSet(this.queryParams).then((response) => {
        this.homePageSetList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        videoOne: null,
        videoTwo: null,
        fieldOne: null,
        fieldTwo: null,
        fieldThree: null,
        fieldFour: null,
        fieldFive: null,
        fieldSix: null,
        fieldSeven: null,
        fieldEight: null,
        fieldNine: null,
        fieldTen: null,
        fieldEleven: null,
        fieldTwelve: null,
        fieldThirteen: null,
        fieldFourteen: null,
        fieldFifteen: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加首页设置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getHomePageSet(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改首页设置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateHomePageSet(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHomePageSet(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除首页设置编号为"' + ids + '"的数据项？')
        .then(function () {
          return delHomePageSet(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "homePageSet/homePageSet/export",
        {
          ...this.queryParams,
        },
        `homePageSet_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
